/**
 * 
 */
package com.Adapters;


import java.util.ArrayList;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import com.Adapters.Items.ItemComment;
import com.Adapters.Items.ItemNotification;
import com.Adapters.Items.ItemPost;
import com.Data.Notifications;
import com.Managers.FragmentManagerClass;


/**
 * @author Chris
 * 
 */
public class NotificationAdapter extends ArrayAdapter<Notifications> {

    @Override
    public void clear() {

        rows.clear();

    }

    public boolean contains(Notifications not) {

        for (int i = 0; i < rows.size(); i++) {
            ItemPost p = rows.get(i);
            if (p.getPostId() == not.getIdNotification())
                return true;

        }
        return false;
    }

    private ArrayList<ItemPost> rows;

    /**
     * @param context
     * @param textViewResourceId
     */
    public NotificationAdapter(Context context, int textViewResourceId) {

        super(context, textViewResourceId);
        rows = new ArrayList<ItemPost>();

    }

    @Override
    public void add(Notifications comment) {

        rows.add(new ItemNotification(LayoutInflater.from(getContext()), comment, this));

    }

    @Override
    public int getCount() {

        return rows.size();
    }

    @Override
    public Notifications getItem(int position) {

        return ((ItemNotification) rows.get(position)).getNotification();
    }

    public ItemComment getItemComment(int position) {

        return ((ItemComment) rows.get(position));
    }

    @Override
    public long getItemId(int position) {

        return ((ItemNotification) rows.get(position)).getPostId();
    }

    @Override
    public int getItemViewType(int position) {

        return rows.get(position).getViewType();
    }

    @Override
    public View getView(int position, View v, ViewGroup parent) {

        return rows.get(position).getView(v, position);
    }

    @Override
    public int getViewTypeCount() {

        return 1;
    }

    @Override
    public void remove(Notifications object) {

        for (int i = 0; i < rows.size(); i++) {
            ItemPost p = rows.get(i);
            if (object.getIdNotification() == p.getPostId()) {
                rows.remove(i);
                notifyDataSetChanged();
            }
        }
        if (getCount() == 0)
            FragmentManagerClass.aNotifications.setNoItemsPopUp();

    }

}
